Skip to content

Conversation

@truffle0
Copy link
Contributor

Adds a function to test hibernation/resume in QEMU during testing, had to make a few changes to the testing code to get it to work property:

  • removed the -no-reboot parameter from the QEMU cmdline, as it needs to be able to reboot internally to work. Initially I considered using the test_resume function in /sys/power/disk, however this just seems to hang QEMU :(

  • the test module now also checks for the kernel panic dmesg line from QEMU, since without the -no-reboot arg it will just hang or reboot if it panics.

-test_flag is now printed at the end of the test rootfs script in the init_final stage, to enable adding functions to the init_main stage.

  • added a resume_tests function to the test_image module (which can be activated by the test_resume parameter), which will hibernate the kernel and trigger a reboot. The test is successful if it continues from the same point in the script after resume.

  • the test_resume parameter also activates extra code in the test_image builder that uses sgdisk to configure a swap partition (this was added in a previous PR). Current this partition is not within the encrypted section of the disk, in future it would ideally detect the users layout and somewhat-mimic that on the test disk.

  • changed the default size of the test rootfs disk to 256M, from 16M. I needed to include 128M for the swap to ensure it doesn't run out of memory when hibernating (this is technically not enough for all the RAM, but the kernel shouldn't need more if it's just running a single bash script as init). This also adds an extra 128M at the end for filesystems, as I found that things like Btrfs have a minimum size of 30-40M, so it would fail to build anyways.

  • changed the shebang for the test image to include #!/bin/sh -l, as it now needs to import /etc/profile for the extra test functions

I'm not sure whether enable the resume tests by default, I figured it's best not to in case it's not supported on a target system, auto-detection could be the next thing.

Also funny story, I spent a while rewriting the testing function to use the subprocess module and read the QEMU output in real time, only rebase and find it had already been added. Teaches me to not leave rebasing till the end :)

@truffle0
Copy link
Contributor Author

Squashed the 4 commits that I originally submitted so it makes a bit more sense

@truffle0
Copy link
Contributor Author

truffle0 commented May 2, 2025

Separate the hibernate/resume test code into a different module called test_resume.
Also made a few changes to make including swap in the test image less dependent on the test_resume parameter, so it would make sense to use with other modules (I feel like that part is still a little janky though tbh, ideally wanted to make including swap more central but didn't want to play round with the test module too much more)

@truffle0
Copy link
Contributor Author

truffle0 commented May 5, 2025

Finally got that fix in for the script and reworked the way it handles the test-specific variables a bit, got stuck for a while on the latter.

Originally I tried to include them all as custom_parameters in the module, but ran into issues with the list variables being overridden and losing their original values. Currently it only modifies the variables in the build_pre stage, and checks if the test module is included to avoid errors.

I'm not entirely sure if it's the correct way to go about implementing it, but I thought this way it's a bit cleaner and says out of the way of other modules as much as possible :)

truffle0 added 4 commits July 12, 2025 22:27
builds successfully, but still need to figure out why qemu fails
- added a resume test to `test_image` which does a simple
  hibernate/resume of the VM, and triggers a panic if it fails

- removed "-no-reboot" parameter, needed for full resume test, and added
  a check for kernel panic messages to stop QEMU from rebooting
  indefinitely

- changed default size of test_rootfs from 16M to 256M to allow 128M of swap for
  testing (left 128M for disk as it's necessary for certain filesystem,
  like btrfs which enforces minimum partition size of 40M)

- `test_resume` parameter (off by default), enables most of the extra
  functionality for resume testing

- wrote a `resume_tests` function for the `test_image` with script to
  very hibernate/reboot returns to the same point

- rearranged functions in the `test_image` module so that the
  `test_flag` is printed in the `init_final` stage in the `complete_tests`
  function, allows tests in `init_main` to be run before passing

- changed shebang for `test_image` module to include "-l" to load
  `/etc/profile` in the test image

- added the `swapon` binary to the `test_image`, so the resume swap file
  can be mounted before hibernation

quick format fixes for previous commit
- added the `test_modules` parameter to to specify which modules to
  include in test image.

- the `test_resume` parameter now includes the extra hibernate/resume
  testing function

- including swap in the test image now works off the `test_swap_uuid`
  parameter, so it's less dependent on the resume module. would still
  be ideal to fix up the code that builds the swap at some point.
- converted `test_cmdline` to a NoDupFlatList to allow modules to append
  parameters more easily

- made script in `test_resume` posix compliant, removed use of "local",
  "source" and (technically compliant, but not universally supported)
  redirects

- attempted to clean up test-specific variables that are appended to by
  the resume module.
truffle0 added 2 commits July 12, 2025 23:38
it enables late resume, but doesn't really create the conditions to test
it, could make it work with cryptsetup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant